const rp  = require('request-promise')
var Agent = require('socks5-https-client/lib/Agent');
module.exports =  async function requestData(app) {
  function request(url) {
    return rp({
      url: url,
      json: true,
      strictSSL: true,
      agentClass: Agent,
      agentOptions: {
        socksHost: 'localhost', // Defaults to 'localhost'.
        socksPort: 1086, // Defaults to 1080.
      }
    });
  }
  const result = await request('https://www.huobi.com/-/x/hb/p/api/contents/pro/single_page/?r=314fx3tkha4&lang=en-us&pageType=1')
  const data = result.data;
  debugger
  app.service('coin-type')
  .create(data);
  /*const subResult= (await request(`https://www.huobi.com/-/x/hb/p/api/contents/pro/currency_introduction?r=shrq3a7xc3&currency=ven&lang=zh-cn`)).data
  if(subResult) {
    const {publishTime, publishVolume, circulateVolume, crowdfundingPrice, officialWebsite, whitePaper, blockQuery} = subResult
    app.service('coin-type').patch(205,{
      publish_Time:publishTime,
      publish_volume:publishVolume,
      circulate_volume:circulateVolume,
      crowdfunding_Price: crowdfundingPrice,
      official_Website:officialWebsite,
      white_Paper:whitePaper,
      block_Query:blockQuery
    });
  }*/
  /*const result = await app.service('coin-type').find({
    paginate: false
  })
  result.forEach(async item => {
    try {
      const subResult= (await request(`https://www.huobi.com/-/x/hb/p/api/contents/pro/currency_introduction?r=shrq3a7xc3&currency=${item.name}&lang=zh-cn`)).data
      if(subResult) {
        const {publishTime, publishVolume, circulateVolume, crowdfundingPrice, officialWebsite, whitePaper, blockQuery} = subResult
        app.service('coin-type').patch(item.id,{
          publish_Time: publishTime,
          publish_volume:publishVolume,
          circulate_volume:circulateVolume,
          crowdfunding_Price: crowdfundingPrice,
          official_Website:officialWebsite,
          white_Paper:whitePaper,
          block_Query:blockQuery
        });
      }
    } catch (e) {
      console.log(e);
    }
  });*/
}
